sp_configure 'clr enabled', 1
go
reconfigure
GO
CREATE DATABASE GenMeta
GO
CREATE SCHEMA Meta
GO
ALTER DATABASE GenMeta SET TRUSTWORTHY ON
GO
DROP FUNCTION Meta.GetFrequency
GO
DROP FUNCTION Meta.GetMicrosPast
GO
DROP FUNCTION Meta.GetMs
GO
DROP FUNCTION Meta.GetTickCount
GO
DROP FUNCTION Meta.GetTicksPast
GO
DROP FUNCTION Meta.GetTime
GO
DROP FUNCTION Meta.GetTimeAsString
GO
DROP ASSEMBLY MeasureTime
GO
CREATE ASSEMBLY MeasureTime AUTHORIZATION [dbo]
FROM ...
WITH PERMISSION_SET = UNSAFE
GO
CREATE FUNCTION Meta.GetFrequency() RETURNS bigint AS  EXTERNAL NAME MeasureTime.UserDefinedFunctions.GetFrequency
GO
CREATE FUNCTION Meta.GetMicrosPast(@zero bigint) RETURNS bigint AS  EXTERNAL NAME MeasureTime.UserDefinedFunctions.GetMicrosPast
GO
CREATE FUNCTION Meta.GetMs() RETURNS bigint AS  EXTERNAL NAME MeasureTime.UserDefinedFunctions.GetMs
GO
CREATE FUNCTION Meta.GetTickCount() RETURNS bigint AS  EXTERNAL NAME MeasureTime.UserDefinedFunctions.GetTickCount
GO
CREATE FUNCTION Meta.GetTicksPast(@zero bigint) RETURNS bigint AS  EXTERNAL NAME MeasureTime.UserDefinedFunctions.GetTicksPast
GO
CREATE FUNCTION Meta.GetTime() RETURNS datetime AS EXTERNAL NAME MeasureTime.UserDefinedFunctions.GetTime
GO
CREATE FUNCTION Meta.GetTimeAsString() RETURNS nvarchar(4000) AS  EXTERNAL NAME MeasureTime.UserDefinedFunctions.GetTimeAsString
GO
EXEC ('DROP TABLE #theTime')
GO
CREATE TABLE #theTime (d datetime, t datetime, ticks bigint, microSecs bigint)
INSERT #theTime VALUES (GetDate(), Meta.GetTime(), Meta.GetTicksPast(0), Meta.GetMicrosPast(0))
INSERT #theTime VALUES (GetDate(), Meta.GetTime(), Meta.GetTicksPast(0), Meta.GetMicrosPast(0))
INSERT #theTime VALUES (GetDate(), Meta.GetTime(), Meta.GetTicksPast(0), Meta.GetMicrosPast(0))
INSERT #theTime VALUES (GetDate(), Meta.GetTime(), Meta.GetTicksPast(0), Meta.GetMicrosPast(0))
SELECT *,Meta.GetTicksPast(0) FROM #theTime
SELECT Meta.GetTimeAsString(), Meta.GetTimeAsString(), Meta.GetTicksPast(0), Meta.GetTicksPast(0), Meta.GetTicksPast(0), Meta.GetTicksPast(0)
GO
